<meta charset="utf-8">
<?php
	
	/* include_once('init.php');*/
	/*print_r($_POST);*/
	/*判断点击提交了数据*/
	if(!empty($_POST)) {
		/*连接数据库*/
		if (empty($_COOKIE['auto']) && !empty($_POST['username']) && empty($_POST['passsword'])) {
			
			}
		/*给$_POST里的数据一个声明*/

		$username=$_POST['username'];
		$password=md5($_POST['password']);//b2ca678b4c936f905fb82f2733f5297f
		$code=$_POST['code'];
		/*echo strtolower($_SESSION['code']);
		echo '<br>';
		echo $code;die;*/
		
		
		if($_POST['password']==!empty($_COOKIE['password'])) {
			$password=$_COOKIE['password'];
			// echo $password;
		};
			
		/*查询sql里的数据，给查询语句一个声明*/
		// $sql = "select * from `admin` where `username`='$username' and `password`='$password'";
		 /*给$link数据库执行查询语句，给执行语句一个声明*/
		// $c=mysqli_query($link,$sql);
		/*执行语句后得出的数据获取一条真实的数据*/
		// $sancu=mysqli_fetch_assoc($c);
		$where['username']=$username;
		$where['password']=$password;

		$sancu=getselectByone('`admin`,`role`',"`admin`.role_id=`role`.id and `username`='$username' and `password`='$password'");

		/*print_r($sancu);die;*/

		/*判断是不是和数据库里的数据库相同*/
		if (!$sancu && $code==strtolower($_SESSION['code'])){
			/*没有和数据库里面的数据相同，输出错误*/
			echo '<script>alert("用户名或密码错误");history.go(-1);</script>';die;
		}else{
			/*和数据库里面的数据相同，输出正确*/
			/*echo '<script>alert("登录成功");history.go(-1);</script>';*/
			 
			
			/*session_start();*/

			// $sancu=explode(',',$sancu);
 
			$_SESSION['admin']=$sancu;
			/*print_r($_SESSION);die;*/
			if (!empty($_POST['check'])) {
				setcookie('username',$username,time()+3600*24*30*12);
				setcookie('password',$password,time()+3600*24*30*12);
			}else{
				// echo "string";die;
				setcookie('username','',0);
				setcookie('password','',0);
			}
			if (!empty($_POST['auto'])) {
				setcookie('auto_login',1,time()+3600*24*30*12);
				
			}else{
				setcookie('auto_login',0,0);
				
			}

			header('location:index.php?c=index&a=index&admin=1');
		}
	  
	}

		include( VIEW_PATH.$admin.'admin/login.html');



 




?>

